package com.javabasic.algorithm.sword_of_offer;

/**
 * @Author xiongmin
 * @ClassName 二维数组中的查找
 * @Description TODO
 * @Date 2019/9/7 21:35
 * @Version 1.0
 **/
public class 二维数组中的查找 {

    private boolean flag = false;
    public boolean Find(int target, int [][] array) {
        dfs(target,array.length,array[0].length,0,0,array);
        return flag;


    }
    public void dfs(int target, int row, int col, int x, int y,int [][] array){
        if (flag) return;
        if (x >= row) return;
        if (y >= col) return;
        if (array[x][y] == target) {
            flag = true;
            return;
        }

        if (array[x][y] > target) return;

        if (array[x][y] < target) {
            dfs( target,  row,  col,  x+1,  y, array);
            dfs( target,  row,  col,  x,  y+1, array);
        }
    }

}
